#pragma once

#include "material.h"
#include "geom.h"

#include <memory>
#include <vector>
using namespace std;

struct Model
{
	Material material;
	shared_ptr<Geometry> geometry;
};


typedef vector<Model> ModelGroup;



inline void serialize_model(Model& model, ostream& out)
{
	serialize_material(model.material, out);
	serialize_geometry(model.geometry, out);
}
inline Model deserialize_model(istream& in)
{
	Model model;
	model.material = deserialize_material(in);
	model.geometry = deserialize_geometry(in);
	return model;
}


inline void serialize_model_group(ModelGroup& model_group, ostream& out)
{
	uint count = model_group.size();
	out.write((char*)&count, sizeof(decltype(count)));
	for(uint i = 0; i < model_group.size(); i++)
	{
		serialize_model(model_group[i], out);
	}
}
inline ModelGroup deserialize_model_group(istream& in)
{
	ModelGroup mg;
	uint count;
	in.read((char*)&count, sizeof(decltype(count)));
	for(uint i = 0; i < count; i++)
	{
		mg.push_back(deserialize_model(in));
	}
	return mg;
}
